<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>运营角色管理</title>
<script type="text/javascript">
	$(function() {
		$.jgrid.ajaxOptions.type = 'post';
		$("#gridTable")
				.jqGrid(
						{
							url : 'cms/role/view',
							datatype : "json",
							autowidth : true,
							rownumbers : true,
							height : 270,
							colNames : [ 'id', '角色名称', '角色编号', '业务类型','是否默认角色', '操作' ],
							colModel : [ {
								name : 'id',
								index : 'id',
								hidden : true
							}, {
								name : 'name',
								index : 'name',
								width : 90
							},  {
								name : 'code',
								index : 'code',
								width : 80
							}, {
								name : 'systemCode',
								index : 'systemCode',
								width : 80
							}, {
								name : 'defaultFlag',
								index : 'defaultFlag',
								width : 50
							}, {
								name : 'oper',
								index : 'oper',
								width : 90
							} ],
							viewrecords : true,
							rowNum : 10,
							rowList : [ 10, 20 ],
							gridComplete : function() {
								var ids = jQuery("#gridTable").jqGrid(
										'getDataIDs');
								for ( var i = 0; i < ids.length; i++) {
									var rowdata = jQuery("#gridTable")
											.getRowData(ids[i]);
									var id = rowdata['id'];
									jQuery("#gridTable")
											.jqGrid(
													'setRowData',
													ids[i],
													{
														/* oper : '<shiro:hasPermission name="role:modify"><a class="btn" href="#" onclick="modifyDialog('
																+ id
																+ ')">修改</a> </shiro:hasPermission>'
																+ '<shiro:hasPermission name="role:auths"><a class="btn" href="#" onclick="permisDialog('
																+ id
																+ ')">授权</a> </shiro:hasPermission>'
																+ ' <shiro:hasPermission name="role:delete"><a class="btn" href="#" onclick="delDialog('
																+ id
																+ ')">删除</a> </shiro:hasPermission>'
																+ ' <shiro:hasPermission name="role:config"><a class="btn" href="#" onclick="configDefault('
																+ id
																+ ','
																+ rowdata['defaultFlag']
																+ ')">'
																+ (rowdata['defaultFlag'] == 0 ? '设为默认'
																		: '取消默认')
																+ '</a> </shiro:hasPermission>' */
																
														oper : '<a class="btn" href="#" onclick="modifyDialog('
															+ id
															+ ')">修改</a> '
															+ '<a class="btn" href="#" onclick="permisDialog('
															+ id
															+ ')">授权</a> '
															+ '<a class="btn" href="#" onclick="delDialog('
															+ id
															+ ')">删除</a> '
															+ '<a class="btn" href="#" onclick="configDefault('
															+ id
															+ ','
															+ rowdata['defaultFlag']
															+ ')"> '
															+ (rowdata['defaultFlag'] == 0 ? '设为默认'
																	: '取消默认')
															+ '</a>'
													});
									if (rowdata['defaultFlag'] == 0) {
										$("#gridTable").jqGrid("setRowData",
												ids[i], {
													defaultFlag : '否'
												});
									} else {
										$("#gridTable").jqGrid("setRowData",
												ids[i], {
													defaultFlag : '是'
												});
									}
								}
							},
							jsonReader : {
								root : "data",
								page : "index",
								total : "total",
								records : "totalRecord",
								repeatitems : false
							},
							pager : "#pgtoolbar1"
						});
	});

	function search() {
		var param = {
			name : $('#name').val(),
			code : $('#code').val(),
			systemCode : $('#systemCode').val(),
			source : $('#source').val(),
			roleLevel : $('#roleLevel').val(),
			defaultFlag : $('#defaultFlag').val()
		};
		
		$("#e_name").val($('#name').val());
		$("#e_code").val($('#code').val());
		$("#e_systemCode").val($('#systemCode').val());
		$("#e_source").val($('#source').val());
		$("#e_roleLevel").val($('#roleLevel').val());
		$("#e_defaultFlag").val($('#defaultFlag').val());
		
		var postData = $("#gridTable").jqGrid("getGridParam", "postData");
		$.extend(postData, param);
		$("#gridTable").jqGrid("setGridParam").trigger("reloadGrid", [ {
			page : 1
		} ]);
	}
</script>
</head>
<body>
	<div class="r_location">
		<i class="r_txtico"></i> 运营管理 &gt; 运营角色管理
	</div> 

	<form id="rForm" action="" method="POST">
		<ul class="all_list">
			<li>
				<span class="all_title">角色名称：</span> 
				<span><input type="text" id="name" name="name" class="ui_input" /></span>
				<span class="all_title">是否默认角色:</span> 
				 <span> <select name="defaultFlag" id="defaultFlag">
						<option value="">请选择</option>
						<option value="0">非默认角色</option>
						<option value="1">默认角色</option>
						</select>
				</span> 
				<span class="all_title">角色编号：</span> 
				<span><input type="text" id="code" name="code" class="ui_input" /></span>
			</li>
			<li>
				<span class="all_title"></span> 
				<span><input type="button"
					onclick="search()" value="查询" class="search_btn m-r15" /> <input
					type="reset" value="重置" class="reset_btn" /> <input type="button"
					onclick="exportRole()" value="导出" class="search_btn m-r15" /></span>
			</li>
		</ul>
		<div class="clearfix table_fn">
			<span class="l">运营角色管理数据列表</span> <span class="r"
				style="_margin-top: 5px;"> <shiro:hasPermission
					name="role:add">
					<a href="#" title="" class="add_ico" onclick="addDialog()"
						id="add_term">新增</a>
				</shiro:hasPermission>
			</span>
		</div>
		<table id="gridTable">
		</table>
		<div id="pgtoolbar1"></div>
	</form>
	<form id="e_form" action="" method="POST">
		<input type="hidden" id="e_name" name="name" />
		<input type="hidden" id="e_code" name="code" />
		<input type="hidden" id="e_systemCode" name="systemCode" />
		<input type="hidden" id="e_source" name="source" />
		<input type="hidden" id="e_roleLevel" name="roleLevel" />
		<input type="hidden" id="e_defaultFlag" name="defaultFlag" />
	</form>
	<script type="text/javascript">
		var myDialog;

		function addDialog() {
			showDialog('role/add/page', {
				width : '600px',
				title : '角色添加',
				lock : true
			});
		}

		function modifyDialog(id) {
			showDialog('cms/role/modify/page?id=' + id + '&rand=' + Math.random(),
					{
						width : '600px',
						title : '角色修改',
						lock : true
					});
		}

		function permisDialog(id) {
			showDialog('cms/role/auths/page/' + id + '?rand=' + Math.random(), {
				width : '650px',
				title : '角色授权',
				lock : true
			});
		}

		function exportRole() {
			$('#e_form').attr("action", "role/export_role");
			$('#e_form').get(0).submit();
		}

		function configDefault(id, flag) {
			myDialog = art.dialog({
				lock : true,
				content : flag == 0 ? '确定设置为默认角色？' : '确定取消默认角色？',
				ok : function() {
					$.ajax({
						url : 'role/config?roleId=' + id + '&flag=' + flag,
						tokenId: 'role_default',
						success : function(data) {
							art.dialog({
								icon : data.success,
								content : data.message,
								lock : true
							}).time(3);
							$("#gridTable").trigger("reloadGrid", [ {
								page : 1
							} ]);
						}
					});
				},
				cancelVal : '关闭',
				cancel : true
			//为true等价于function(){}
			});

		}

		function delDialog(id) {
			jQuery.ajax({
				url : 'role/del/check?roleId=' + id,
				success : function(data) {
					if (data.success == 'succeed') {
						myDialog = art.dialog({
							lock : true,
							content : '是否确定删除此角色?',
							ok : function() {
								jQuery.ajax({
									url : "role/del/" + id,
									tokenId: 'role_delete',
									success : function(data) {
										myDialog = art.dialog({
											icon : data.success,
											content : data.message,
											lock : true
										});
										$("#gridTable").trigger("reloadGrid",
												[ {
													page : 1
												} ]);
									}
								});
							},
							cancelVal : '关闭',
							cancel : true
						//为true等价于function(){}
						});
					} else {
						myDialog = art.dialog({
							icon : data.success,
							content : data.message,
							lock : true
						});
					}
				}
			});

		}

		function showDialog(url, options) {
			myDialog = art.dialog(options);// 初始化一个带有loading图标的空对话框
			jQuery.ajax({
				url : url,
				success : function(data) {
					myDialog.content(data);// 填充对话框内容
				}
			});
		}
	</script>
</body>
</html>